<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        解题思路：
        - 二分搜索
        - 调用guess函数，来判断中间元素是否是目标值

        解题步骤：
        - 凑够数组的中间元素开始，如果中间元素正好是目标值，则搜索过程结束
        - 如果目标值大于或者小于中间元素，则在数组大于或小于中间元素的那一半中查找
     -->
</head>
<body>
    <script>
        var guessNumber = function(n) {
            let low = 1;
            let high = n;
            while(low<=high) {
                const mid = Math.floor((low + high) / 2);
                const res = guess(mid);
                if (res === 0) {
                    return mid;
                } else if (res === 1) {
                    low = mid + 1;
                } else {
                    high = mid - 1; 
                }
            }
        };
    </script>
</body>
</html>